package nba2kmodtool.filedesc;

import java.util.ArrayList;
import java.util.List;

class IffBlockIndex {
	List<Integer> chunkType;
	List<Long> flagAddrs;
	List<Long> chunkAddrs;
	List<Long> chunkSizes;

	IffBlockIndex() {
		this.chunkType = new ArrayList<Integer>();
		this.flagAddrs = new ArrayList<Long>();
		this.chunkAddrs = new ArrayList<Long>();
		this.chunkSizes = new ArrayList<Long>();
	}

	private void addChunkType(int chunkType) {
		this.chunkType.add(chunkType);
	}

	private void addChunkSize(long chunkSize) {
		this.chunkSizes.add(chunkSize);
	}

	private void addChunkAddr(long chunkAddr) {
		this.chunkAddrs.add(chunkAddr);
	}

	private void addFlagAddr(long flagAddr) {
		this.flagAddrs.add(flagAddr);
	}

	long getStartAddr() {
		return this.chunkAddrs.get(0);
	}

	long getAddr(int index) {
		return this.chunkAddrs.get(index);
	}

	long getSize(int index) {
		return this.chunkSizes.get(index);
	}

	int getIndexCount() {
		return this.chunkType.size();
	}

	/**
	 * @param chunkType
	 * @param flagAddr
	 * @param chunkAddr
	 * @param chunkSize
	 */
	void addIndex(int chunkType, long flagAddr, long chunkAddr, long chunkSize) {
		this.addChunkType(chunkType);
		this.addChunkAddr(chunkAddr);
		this.addChunkSize(chunkSize);
		this.addFlagAddr(flagAddr);
	}

	public String toString() {
		StringBuilder sb = new StringBuilder(super.toString()).append(":\n");
		for (int i = 0; i < this.chunkType.size(); i++) {
			sb.append(String.format("T:0x%X - F:0x%X - A:%X - S:0x%X\n", this.chunkType.get(i), this.flagAddrs.get(i),
					this.chunkAddrs.get(i), this.chunkSizes.get(i)));
		}
		return sb.toString();
	}
}
